
#include "asm/stb7100reg.h"
#include "../../../cpu/sh/init_ram.S"

/*
 * The poke table is a series of long words, in the format
 *
 *       opcode, address, operand, ...
 *
 * An opcode of 0 marks the table end
 */


	.section .data.init, "a"

	.balign 32

__memory_setup_table:

	/*
	 * CLOCKGENA setup PLL0
	 */
	POKE_LONG(STB7100_CLOCKGENA_LOCK, 0xc0de)
	OR_LONG(STB7100_CLOCKGENA_PLL0_CFG, 0x00100000)
	UPDATE_LONG(STB7100_CLOCKGENA_PLL0_CFG, 0xfff7ffff, 0)
#if (INPUT_CLOCK_RATE == 30)
	UPDATE_LONG(STB7100_CLOCKGENA_PLL0_CFG, 0xfff80000, 0x14 | (0xb1 << 8) | (0x0 << 16))
#else
	UPDATE_LONG(STB7100_CLOCKGENA_PLL0_CFG, 0xfff80000, 0x06 | (0x3b << 8) | (0x0 << 16))
#endif
	OR_LONG(STB7100_CLOCKGENA_PLL0_CFG, 0x00080000)
	WHILE_NE(STB7100_CLOCKGENA_PLL0_STATUS, 0x00000001, 0x00000001)
	UPDATE_LONG(STB7100_CLOCKGENA_PLL0_CFG, 0xffefffff, 0)
	POKE_LONG(STB7100_CLOCKGENA_LOCK, 0x0)
	/*
	 * CLOCKGENA setup PLL1
	 */
	POKE_LONG(STB7100_CLOCKGENA_LOCK, 0xc0de)
	POKE_LONG(STB7100_CLOCKGENA_PLL1_BYPASS, 0x00000002)
	UPDATE_LONG(STB7100_CLOCKGENA_PLL1_CFG, 0xfff7ffff, 0)
	IF_DEVID(STB7100_CUT2)
#if (INPUT_CLOCK_RATE == 30)
	  UPDATE_LONG(STB7100_CLOCKGENA_PLL1_CFG, 0xfff80000, 0x0a | (0x80 << 8) | (0x1 << 16))
#else
	  UPDATE_LONG(STB7100_CLOCKGENA_PLL1_CFG, 0xfff80000, 0x09 | (0x80 << 8) | (0x1 << 16))
#endif
	ENDIF
	IF_DEVID(STB7100_CUT1)
#if (INPUT_CLOCK_RATE == 30)
	  UPDATE_LONG(STB7100_CLOCKGENA_PLL1_CFG, 0xfff80000, 0x1e | (0x85 << 8) | (0x0 << 16))
#else
	  UPDATE_LONG(STB7100_CLOCKGENA_PLL1_CFG, 0xfff80000, 0x1b | (0x85 << 8) | (0x0 << 16))
#endif
	ENDIF
	OR_LONG(STB7100_CLOCKGENA_PLL1_CFG, 0x00080000)
	WHILE_NE(STB7100_CLOCKGENA_PLL1_STATUS, 0x00000001, 0x00000001)
	POKE_LONG(STB7100_CLOCKGENA_PLL1_BYPASS, 0x00000000)
	POKE_LONG(STB7100_CLOCKGENA_LOCK, 0x0)
	/*
	 * SYSCONF setup
	 */
	POKE_LONG(STB7100_SYSCONF_SYS_CFG11, 0x080780c0)

	WHILE_NE(STB7100_SYSCONF_SYS_STA12, (1 << 9) | (1 << 19), (1 << 9) | (1 << 19))
	WHILE_NE(STB7100_SYSCONF_SYS_STA13, (1 << 9) | (1 << 19), (1 << 9) | (1 << 19))

	POKE_LONG(STB7100_SYSCONF_SYS_CFG12, 0x4000000f | (0xf << 12) | (0xf << 23))
	POKE_LONG(STB7100_SYSCONF_SYS_CFG13, 0x4000000f | (0xf << 12) | (0xf << 23))

	IF_DEVID(STB7100_CUT1)
	  POKE_LONG(STB7100_SYSCONF_SYS_CFG14, (1 << 18) | (0x5a << 20))
	  POKE_LONG(STB7100_SYSCONF_SYS_CFG15, (1 << 19) | (0xa9 << 20))
	  POKE_LONG(STB7100_SYSCONF_SYS_CFG20, (1 << 18) | (0x5a << 20))
	  POKE_LONG(STB7100_SYSCONF_SYS_CFG21, (1 << 19) | (0xa9 << 20))
	ENDIF

	/*
	 * LMI SYS setup
	 */
	POKE_LONG(ST40_LMI_MIM_0(SYS), 0x061a0247)
	POKE_LONG(ST40_LMI_MIM_1(SYS), 0x01010022)

	POKE_LONG(ST40_LMI_STR(SYS), 0x35b06455)

	POKE_LONG(ST40_LMI_SDRA0(SYS), 0x08001900)
	POKE_LONG(ST40_LMI_SDRA1(SYS), 0x08001900)

	POKE_LONG(ST40_LMI_SCR(SYS), 0x00000001)
	POKE_LONG(ST40_LMI_SCR(SYS), 0x00000003)
	POKE_LONG(ST40_LMI_SCR(SYS), 0x00000001)
	POKE_LONG(ST40_LMI_SCR(SYS), 0x00000002)

	POKE_LONG(ST40_LMI_SDMR0(SYS), 0x00000400)
	POKE_LONG(ST40_LMI_SDMR0(SYS), 0x00000133)
	POKE_LONG(ST40_LMI_SCR(SYS), 0x00000002)
	POKE_LONG(ST40_LMI_SCR(SYS), 0x00000004)
	POKE_LONG(ST40_LMI_SCR(SYS), 0x00000004)
	POKE_LONG(ST40_LMI_SCR(SYS), 0x00000004)
	POKE_LONG(ST40_LMI_SDMR0(SYS), 0x00000033)
	POKE_LONG(ST40_LMI_SCR(SYS), 0x00000000)

	/*
	 * LMI VID setup
	 */
	POKE_LONG(ST40_LMI_MIM_0(VID), 0x061a0247)
	POKE_LONG(ST40_LMI_MIM_1(VID), 0x01010022)

	POKE_LONG(ST40_LMI_STR(VID), 0x35b06455)
	POKE_LONG(ST40_LMI_SDRA0(VID), 0x14001900)
	POKE_LONG(ST40_LMI_SDRA1(VID), 0x14001900)
	POKE_LONG(ST40_LMI_SCR(VID), 0x00000001)
	POKE_LONG(ST40_LMI_SCR(VID), 0x00000003)
	POKE_LONG(ST40_LMI_SCR(VID), 0x00000001)
	POKE_LONG(ST40_LMI_SCR(VID), 0x00000002)
	POKE_LONG(ST40_LMI_SDMR0(VID), 0x00000402)
	POKE_LONG(ST40_LMI_SDMR0(VID), 0x00000133)
	POKE_LONG(ST40_LMI_SCR(VID), 0x00000002)
	POKE_LONG(ST40_LMI_SCR(VID), 0x00000004)
	POKE_LONG(ST40_LMI_SCR(VID), 0x00000004)
	POKE_LONG(ST40_LMI_SCR(VID), 0x00000004)
	POKE_LONG(ST40_LMI_SDMR0(VID), 0x00000033)
	POKE_LONG(ST40_LMI_SCR(VID), 0x00000000)
	/*
	 * EMI setup
	 */
	POKE_LONG(ST40_EMI_BANK_ENABLE, 0x00000005)

	POKE_LONG(ST40_EMI_BANK0_BASEADDRESS, 0x00000000)
	POKE_LONG(ST40_EMI_BANK1_BASEADDRESS, 0x00000004)
	POKE_LONG(ST40_EMI_BANK2_BASEADDRESS, 0x00000008)
	POKE_LONG(ST40_EMI_BANK3_BASEADDRESS, 0x0000000a)
	POKE_LONG(ST40_EMI_BANK4_BASEADDRESS, 0x0000000c)
	/* FLASH */
	POKE_LONG(ST40_EMI_BANK0_EMICONFIGDATA0, 0x001016d1)
	POKE_LONG(ST40_EMI_BANK0_EMICONFIGDATA1, 0x9d200000)
	POKE_LONG(ST40_EMI_BANK0_EMICONFIGDATA2, 0x9d220000)
	POKE_LONG(ST40_EMI_BANK0_EMICONFIGDATA3, 0x00000000)
	/* EPLD & LAN91C111 */
	POKE_LONG(ST40_EMI_BANK2_EMICONFIGDATA0, 0x042086f1)
	POKE_LONG(ST40_EMI_BANK2_EMICONFIGDATA1, 0x88112111)
	POKE_LONG(ST40_EMI_BANK2_EMICONFIGDATA2, 0x88112211)
	POKE_LONG(ST40_EMI_BANK2_EMICONFIGDATA3, 0x00000000)
	/* ATAPI */

	IF_DEVID(STB7100_CUT1)
	  POKE_LONG(ST40_EMI_BANK3_EMICONFIGDATA0, 0x00021791)
	  POKE_LONG(ST40_EMI_BANK3_EMICONFIGDATA1, 0x08004141)
	  POKE_LONG(ST40_EMI_BANK3_EMICONFIGDATA2, 0x08004141)
	ENDIF
	IF_DEVID(STB7100_CUT2)
	  POKE_LONG(ST40_EMI_BANK3_EMICONFIGDATA0, 0x00200791)
	  POKE_LONG(ST40_EMI_BANK3_EMICONFIGDATA1, 0x0c006700)
	  POKE_LONG(ST40_EMI_BANK3_EMICONFIGDATA2, 0x0c006700)
	ENDIF
	POKE_LONG(ST40_EMI_BANK3_EMICONFIGDATA3, 0x00000000)

	/* Program other EMI registers */
	IF_DEVID(STB7100_CUT1)
	  POKE_LONG(ST40_EMI_GENCFG, 0x00000010)
	ENDIF
	IF_DEVID(STB7100_CUT2)
	  POKE_LONG(ST40_EMI_GENCFG, 0x00000050)
	ENDIF
	END_MARKER

__memory_setup_table_end:

	.end
